package net.halflite.mzkr.form.home;

import java.io.Serializable;

import net.halflite.mzkr.entity.RegistedUser;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.seasar.framework.container.annotation.tiger.Component;
import org.seasar.framework.container.annotation.tiger.InstanceType;
import org.seasar.struts.annotation.Arg;
import org.seasar.struts.annotation.Maxlength;
import org.seasar.struts.annotation.Minlength;
import org.seasar.struts.annotation.Msg;
import org.seasar.struts.annotation.Required;
import org.seasar.struts.annotation.Validwhen;

/** パスワード変更用ActionForm */
@Component(instance = InstanceType.SESSION)
public class PasswordForm implements Serializable {

	private static final long serialVersionUID = 1L;

	/** 現在のパスワード */
	@Required(arg0 = @Arg(key = "現在のパスワード", resource = false))
	public String recent;

	/** パスワード */
	@Required(arg0 = @Arg(key = "新しいパスワード", resource = false))
	@Minlength(minlength = RegistedUser.MIN_PASSWORD_LENGTH, 
			arg0 = @Arg(key = "新しいパスワード", resource = false))
	@Maxlength(maxlength = RegistedUser.MAX_PASSWORD_LENGTH, 
			arg0 = @Arg(key = "新しいパスワード", resource = false))
	@Validwhen(test = "((*this* == null) or (*this* != recent))",
			msg = @Msg(key = "errors.confirm.equal"),
			arg0 = @Arg(key = "新しいパスワード", resource = false),
			args = @Arg(key = "現在のパスワード", resource = false, position = 1))
	public String password;

	/** パスワード確認 */
	@Validwhen(test = "((password == null) or (*this* == password))",
			msg = @Msg(key = "errors.confirm.not.equal"),
			arg0 = @Arg(key = "新しいパスワード", resource = false))
	public String confirm;
	
	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}
}
